<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui.form小例子</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
</head>
<body>
<div style="width:100%;">
    <div style="margin: 200px auto;width:600px;height:500px;border:1px #E0E0E0 solid;">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>用户登录</legend>
        </fieldset>
        <div class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" id="loginName" name="loginName" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="password" name="password" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*" id="login">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
        </div>
    </div>
</div>
</body>
<script src="/plugins/jquery/jquery.min.js?v=1.12.4"></script>
<script src="/plugins/layui/layui.js"></script>
<script>
    layui.use('form', function(){
        var form = layui.form;
        //各种基于事件的操作，下面会有进一步介绍
    });
    $(function(){
        $("#login").click(function(){
            var loginName = $("#loginName").val();
            var password = $("#password").val();
            $.post("/login.json",
                {loginName:loginName,password:password},
                function(data){
                    if(data.code==200){
                        location="/index.html"
                    }else{
                        layer.msg(data.msg);
                        // layer.open({
                        //     title: '登陆'
                        //     ,content: data.data
                        // });
                    }
                }
            );
        })
    });
</script>